using System;
using System.Diagnostics;
using System.IO;

namespace DirectoryWatcher
{
    /// <summary>
    /// Represents a program that we should execute and the details about the filesystem event that
    /// it's being run in response to.
    /// </summary>
    public struct ExecutionInstance
    {
        /// <summary>
        /// The path, arguments, and options for the process that we should start.
        /// </summary>
        public ProcessStartInfo StartInfo;
        /// <summary>
        /// The path to the file for which this program is being executed.
        /// </summary>
        public string FilePath;
        /// <summary>
        /// The filesystem event type for which the program is being executed.
        /// </summary>
        public WatcherChangeTypes EventType;
        /// <summary>
        /// Flag indicating whether or not we should redirect the file to the process' standard input stream.
        /// </summary>
        public bool RedirectFileToStdin;
        /// <summary>
        /// Interface to the runtime-compiled class that we are to invoke to handle the event.
        /// </summary>
        public IFileSystemEventHandler EventHandler;

        /// <summary>
        /// Constructor that initializes the process info for this execution instance.
        /// </summary>
        /// <param name="startInfo">
        /// The path, arguments, and options for the process that we should start.
        /// </param>
        /// <param name="eventType">
        /// The filesystem event type for which the program is being executed.
        /// </param>
        /// <param name="filePath">
        /// The path to the file for which this program is being executed.
        /// </param>
        public ExecutionInstance(ProcessStartInfo startInfo, WatcherChangeTypes eventType, string filePath)
        {
            StartInfo = startInfo;
            EventType = eventType;
            FilePath = filePath;
            RedirectFileToStdin = false;
            EventHandler = null;
        }

        /// <summary>
        /// Constructor that initializes the process info and standard input file flag for this 
        /// execution instance.
        /// </summary>
        /// <param name="startInfo">
        /// The path, arguments, and options for the process that we should start.
        /// </param>
        /// <param name="eventType">
        /// The filesystem event type for which the program is being executed.
        /// </param>
        /// <param name="filePath">
        /// The path to the file for which this program is being executed.
        /// </param>
        /// <param name="redirectFileToStdin">
        /// Flag indicating whether or not we should redirect the file to the process' standard 
        /// input stream.
        /// </param>
        public ExecutionInstance(ProcessStartInfo startInfo, WatcherChangeTypes eventType, string filePath, bool redirectFileToStdin)
        {
            StartInfo = startInfo;
            EventType = eventType;
            FilePath = filePath;
            RedirectFileToStdin = redirectFileToStdin;
            EventHandler = null;
        }

        /// <summary>
        /// Constructor that initializes the event handler class interface for this execution
        /// instance.
        /// </summary>
        /// <param name="eventHandler">
        /// Interface to the runtime-compiled class that we are to invoke to handle the event.
        /// </param>
        /// <param name="eventType">
        /// The filesystem event type for which the program is being executed.
        /// </param>
        /// <param name="filePath">
        /// The path to the file for which this program is being executed.
        /// </param>
        public ExecutionInstance(IFileSystemEventHandler eventHandler, WatcherChangeTypes eventType, string filePath)
        {
            StartInfo = null;
            EventType = eventType;
            FilePath = filePath;
            RedirectFileToStdin = false;
            EventHandler = eventHandler;
        }
    }
}
